import json
import pandas as pd

def pandas_analysis(file, user_id):
    times = 0
    minutes = 0
    # 读取 JSON 文件
    with open(file, 'r') as ori_file:
        # 读取 JSON 编码格式的数据
        ori_json = json.load(ori_file)
        # 将 JSON 数据转换为 DataFrame
        df = pd.DataFrame(ori_json)
        # 使用 Pandas 选择相应用户的数据
        df_user = df[df['user_id'] == user_id]
        # 统计该用户的总学习次数和总学习时间
        times = len(df_user)
        minutes = df_user['minutes'].sum()

    return times, minutes

a ="./user_study.json"
print(pandas_analysis(a,199071))
